package com.lancoo.znbkxx.teacher.aibkGenerateTestPaper.aibkReviewTestPaper.aibkQuesReviewDXT

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerAdapter
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerViewHolder
import com.lancoo.znbkxx.teacher.aibkTestCoach.aibkTools.LancooMethod
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.aibkGenerateTestPaper.aibkReviewTestPaper.QuesReviewInforIndexHelp.getChildListBean
import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.entity.TestPaperReviewInfor
import com.lancoo.znbkxx.teacher.widget.CustomTextViewToPicture
import kotlinx.android.synthetic.main.aibk_adapter_item_child_xzt.view.*
import kotlinx.android.synthetic.main.aibk_adapter_item_itemanalysis.view.*

class QuesReviewAdapterChildDxt(
        val activity: AppCompatActivity,
        val testPaperReviewInfor: TestPaperReviewInfor,
        val index_A: Int,
        val index_B: Int
) : KBaseRecyclerAdapter() {

    override fun getHolderView(parent: ViewGroup?, position: Int): View {
        var rootView: View? = null
        if (position == getChoiceTotalSize()) {
            rootView = LayoutInflater.from(activity)
                    .inflate(R.layout.aibk_adapter_item_itemanalysis, parent, false)
        } else {
            rootView = LayoutInflater.from(activity)
                    .inflate(R.layout.aibk_adapter_item_child_xzt, parent, false)
        }
        return rootView
    }

    override fun onBindViewHolder(holder: KBaseRecyclerViewHolder, position: Int) {

        if (position == getChoiceTotalSize()) {
            var childAnalysis = getChildListBean(testPaperReviewInfor, index_A, index_B, 0).ChildAnalysis
            CustomTextViewToPicture(activity, holder.convertView.TvItemAnalysis, LancooMethod.getNewItemAnalysis(childAnalysis))
        } else {
            var optionIndex = getChildListBean(testPaperReviewInfor, index_A, index_B, 0).ChildOptionList[position].OptionIndex
            var option = getChildListBean(testPaperReviewInfor, index_A, index_B, 0).ChildOptionList[position].Option
            var showType = getChildListBean(testPaperReviewInfor, index_A, index_B, 0).ChildOptionList[position].ShowType
            if (showType == 0) {
                holder.convertView.BtnOptionIndex.text = optionIndex
                CustomTextViewToPicture(activity, holder.convertView.TvOptionContent, option)
            } else {
                holder.convertView.BtnOptionIndex.text = option
                CustomTextViewToPicture(activity, holder.convertView.TvOptionContent, "")
            }

            var ItemAnswer = getChildListBean(testPaperReviewInfor, index_A, index_B, 0).ItemList[0].ItemAnswer
            if (optionIndex == ItemAnswer) {
                holder.convertView.BtnDuiGou.visibility = View.GONE
                holder.convertView.BtnOptionIndex.setTextColor(activity.resources.getColor(R.color.lancoooWhite))
                holder.convertView.BtnOptionIndex.setBackgroundResource(R.mipmap.aibk_icon_choice_green)
            } else {
                holder.convertView.BtnDuiGou.visibility = View.GONE
                holder.convertView.BtnOptionIndex.setTextColor(activity.resources.getColor(R.color.textColor))
                holder.convertView.BtnOptionIndex.setBackgroundResource(R.mipmap.aibk_icon_choice_white)
            }
        }

    }

    private fun getChoiceTotalSize(): Int {
        return getChildListBean(testPaperReviewInfor, index_A, index_B, 0).ChildOptionList.size
    }

    override fun getItemCount(): Int {
        return getChoiceTotalSize() + 1
    }

    override fun getItemViewType(position: Int): Int {
        return position
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

}